home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / 8bit / cislib_a / dump.act < prev    next >
Text File  |  1995-04-22  |  2KB  |  134 lines

  1. ; Dump - Print the contents of binary
  2. ;   files in hexadecimal and ATASCII
  3.  
  4. ; by Mark Rose - February, 1985
  5.  
  6.  
  7.  
  8. ; A few useful definitions:
  9.  
  10. DEFINE ChunkSize = "8",
  11.        Escape    = "$1B",
  12.        NewLine   = "$9B",
  13.        File      = "1"
  14.  
  15.  
  16.  
  17. ; Print out a byte as two hexadecimal
  18. ; digits.
  19.  
  20. PROC HexByte(BYTE c)
  21.    BYTE ARRAY HexDig(16)=
  22.        ['0 '1 '2 '3 '4 '5 '6 '7
  23.         '8 '9 'A 'B 'C 'D 'E 'F]
  24.  
  25.    Put(HexDig(c RSH 4))
  26.    Put(HexDig(c&15))
  27. RETURN
  28.  
  29.  
  30.  
  31. ; Print out a two-byte value as 4
  32. ; hexadecimal digits by calling
  33. ; HexByte.
  34.  
  35. PROC HexWord(CARD i)
  36.    HexByte(i RSH 8)
  37.    HexByte(i & 255)
  38. RETURN
  39.  
  40.  
  41.  
  42. ; Read in the next few bytes of the
  43. ; file (the desired number is chosen
  44. ; by the value of "ChunkSize").
  45.  
  46. BYTE FUNC ReadChunk( BYTE ARRAY buf )
  47.     BYTE nBytes,
  48.          c
  49.  
  50.     nBytes = 0
  51.     DO
  52.         c = GetD( File )
  53.         IF EOF( File ) THEN
  54.             EXIT
  55.         FI
  56.         buf( nBytes ) = c
  57.         nBytes ==+ 1
  58.       UNTIL nBytes = ChunkSize
  59.     OD
  60. RETURN( nBytes )
  61.  
  62.  
  63.  
  64. ; Put a character to screen.  If char
  65. ; is an ATASCII return, put period,
  66. ; instead, so display isn't messed up.
  67.  
  68. PROC PutChar( BYTE c )
  69.     IF c # NewLine THEN
  70.         Put( Escape )
  71.         Put( c )
  72.     ELSE
  73.         Put( '. )
  74.     FI
  75. RETURN
  76.  
  77.  
  78.  
  79. ; Print hex and ATASCII of chars read
  80. ; by ReadChunk.
  81.  
  82. PROC DumpChunk( CARD offset, BYTE n, BYTE ARRAY buf )
  83.     BYTE i
  84.  
  85.     HexWord( offset )
  86.     Print( ":" )
  87.     FOR i = 0 TO n-1
  88.       DO
  89.         HexByte( buf( i ) )
  90.         Put( '  )
  91.       OD
  92.     FOR i = i TO ChunkSize-1
  93.       DO
  94.         Print( "   " )
  95.       OD
  96.     FOR i = 0 TO n-1
  97.       DO
  98.         PutChar( buf( i ) )
  99.       OD
  100.     PutE()
  101. RETURN
  102.  
  103.  
  104.  
  105. ; Dump a file to screen.
  106.  
  107. PROC Dump()
  108.     BYTE ARRAY fName( 50 )
  109.     CARD offset
  110.     BYTE size
  111.     BYTE ARRAY buf( ChunkSize )
  112.  
  113.   ; First, get file to dump.
  114.     Print( "File: " )
  115.     InputS( fName )
  116.     Close( File )
  117.     Open( File, fname ,4 ,0 )
  118.  
  119.   ; Until end-of-file, read a few chars
  120.   ; and dump them to screen.
  121.     offset = 0
  122.     DO  
  123.         size = ReadChunk( buf )
  124.         IF size = 0 THEN
  125.             EXIT
  126.         FI
  127.         DumpChunk( offset, size, buf )
  128.         offset ==+ size
  129.     OD
  130.  
  131.     Close(1)
  132. RETURN
  133.  
  134. ooooooooooooooooo